home *** CD-ROM | disk | FTP | other *** search
Text File | 1997-04-25 | 10.0 KB | 441 lines | [TEXT/CWIE] |
- // ==================================================
- // UAppleEvents.cp
- // Copyright (C) 1996-1997 Mizutori Tetsuya
- // October 5, 1996; February 6, 1997; April 23, 1997.
- // ==================================================
- // All documents are pretty-printed in 10-point Geneva font.
-
- #include <Aliases.h>
-
- #include <UAppleEventsMgr.h>
- #include <UExtractFromAEDesc.h>
- #include <UMemoryMgr.h>
-
- #include "UAppleEvents.h"
-
- #define longDateTimeHi( a ) (((LongDateCvt *) &(a))->hl.lHigh)
- #define longDateTimeLo( a ) (((LongDateCvt *) &(a))->hl.lLow)
-
-
- // ==================================================
- // • Constructors
- // ==================================================
-
- // --------------------------------------------------
- // • UAppleEvents
- // --------------------------------------------------
-
- UAppleEvents::UAppleEvents()
- {
- }
-
-
- // --------------------------------------------------
- // • UAppleEvents
- // --------------------------------------------------
-
- UAppleEvents::~UAppleEvents()
- {
- }
-
-
- // ==================================================
- // • Common functions
- // ==================================================
-
- // ==================================================
- // • Handling descriptor
- // ==================================================
-
- // --------------------------------------------------
- // • TheLongDateTime
- // --------------------------------------------------
-
- // Making a 'TheLongDateTime()' function from a template.
- // See also examples in the source code 'UExtractFromAEDesc.cp'.
-
- #ifdef COMMENT
- static void
- UAppleEvents::TheLongDateTime(
- const AEDesc & inDesc,
- LongDateTime & outValue );
- #endif // COMMENT
-
- // --------------------------------------------------
- #undef Extractor_Name
- #undef C_DataType
- #undef AE_DataType
-
- #define Extractor_Name TheLongDateTime
- #define C_DataType LongDateTime
- #define AE_DataType typeLongDateTime
-
- #undef UExtractFromAEDesc
- #define UExtractFromAEDesc UAppleEvents
- #include <AEDescExtractor.t>
- #undef UExtractFromAEDesc
- // --------------------------------------------------
-
-
-
- // --------------------------------------------------
- // • TheText
- // --------------------------------------------------
-
- void
- UAppleEvents::TheText(
- const AEDesc & inDesc,
- Handle & outTextH,
- long & outTextLen )
- {
- if ( inDesc.descriptorType != typeChar )
- ThrowOSErr_( errAETypeError );
-
- outTextH = inDesc.dataHandle;
- outTextLen = ::GetHandleSize( outTextH );
- }
-
-
- // --------------------------------------------------
- // • TheFSSpec
- // --------------------------------------------------
-
- void
- UAppleEvents::TheFSSpec(
- const AEDesc & inDesc,
- FSSpec & outFSSpec )
- {
- switch ( inDesc.descriptorType ) {
- case typeFSS:
- {
- outFSSpec = * (FSSpec *) * inDesc.dataHandle;
- }
- break;
-
- case typeAlias:
- {
- StAEDescriptor theDesc;
- OSErr err = ::AECoerceDesc( &inDesc, typeFSS, &theDesc.mDesc );
- ThrowIfOSErr_( err );
- outFSSpec = * (FSSpec *) * theDesc.mDesc.dataHandle;
- }
- break;
-
- default:
- ThrowOSErr_( errAETypeError );
- break;
- }
- }
-
-
- // ==================================================
- // • Handling Apple Event
- // ==================================================
-
- // --------------------------------------------------
- // • GetParamLongDateTime
- // --------------------------------------------------
-
- Boolean
- UAppleEvents::GetParamLongDateTime(
- const AppleEvent & inAppleEvent,
- AEKeyword inKeyword,
- LongDateTime & outValue,
- const unsigned long defaultValue ) // = 0
- {
- Boolean result = true;
- StAEDescriptor theDesc;
-
- theDesc.GetOptionalParamDesc( inAppleEvent, inKeyword, typeLongDateTime );
-
- if ( theDesc.mDesc.descriptorType != typeNull )
- UAppleEvents::TheLongDateTime( theDesc.mDesc, outValue );
- else {
- longDateTimeHi( outValue ) = 0;
- longDateTimeLo( outValue ) = defaultValue;
- result = false;
- }
-
- return result;
- }
-
-
- // --------------------------------------------------
- // • GetParamLong
- // --------------------------------------------------
-
- Boolean
- UAppleEvents::GetParamLong(
- const AppleEvent & inAppleEvent,
- AEKeyword inKeyword,
- long & outValue,
- const long defaultValue ) // = 0
- {
- Boolean result = true;
- StAEDescriptor theDesc;
-
- theDesc.GetOptionalParamDesc( inAppleEvent, inKeyword, typeLongInteger );
-
- if ( theDesc.mDesc.descriptorType != typeNull )
- UExtractFromAEDesc::TheInt32( theDesc.mDesc, outValue );
- else {
- outValue = defaultValue;
- result = false;
- }
-
- return result;
- }
-
-
- // --------------------------------------------------
- // • GetParamEnum
- // --------------------------------------------------
-
- Boolean
- UAppleEvents::GetParamEnum(
- const AppleEvent & inAppleEvent,
- AEKeyword inKeyword,
- OSType & outValue,
- const OSType defaultValue ) // = typeNull
- {
- Boolean result = true;
- StAEDescriptor theDesc;
-
- theDesc.GetOptionalParamDesc( inAppleEvent, inKeyword, typeEnumerated );
-
- if ( theDesc.mDesc.descriptorType != typeNull ) {
- UExtractFromAEDesc::TheEnum( theDesc.mDesc, outValue );
- } else {
- outValue = defaultValue;
- result = false;
- }
-
- return result;
- }
-
-
- // --------------------------------------------------
- // • GetParamBoolean
- // --------------------------------------------------
-
- Boolean
- UAppleEvents::GetParamBoolean(
- const AppleEvent & inAppleEvent,
- AEKeyword inKeyword,
- Boolean & outValue,
- const Boolean defaultValue ) // = true
- {
- Boolean result = true;
- StAEDescriptor theDesc;
-
- theDesc.GetOptionalParamDesc( inAppleEvent, inKeyword, typeBoolean );
-
- if ( theDesc.mDesc.descriptorType != typeNull ) {
- UExtractFromAEDesc::TheBoolean( theDesc.mDesc, outValue );
- } else {
- outValue = defaultValue;
- result = false;
- }
-
- return result;
- }
-
-
- // --------------------------------------------------
- // • GetParamPString
- // --------------------------------------------------
-
- Boolean
- UAppleEvents::GetParamPString(
- const AppleEvent & inAppleEvent,
- AEKeyword inKeyword,
- Str255 outString,
- const StringPtr defaultString ) // = "\p"
- {
- Boolean result = true;
- StAEDescriptor theDesc;
-
- theDesc.GetOptionalParamDesc( inAppleEvent, inKeyword, typeChar );
-
- if ( theDesc.mDesc.descriptorType != typeNull ) {
- UExtractFromAEDesc::ThePString( theDesc.mDesc, outString );
- } else {
- // UTextword::PStrCopy( outString, defaultString );
- ::BlockMoveData( &defaultString[0], &outString[0], defaultString[0]+1 );
- result = false;
- }
-
- return result;
- }
-
-
- // --------------------------------------------------
- // • GetParamText
- // --------------------------------------------------
-
- Boolean
- UAppleEvents::GetParamText(
- const AppleEvent & inAppleEvent,
- AEKeyword inKeyword,
- Handle theTextH,
- long & theTextLen )
- {
- Boolean result = true;
- StAEDescriptor theDesc;
-
- theDesc.GetOptionalParamDesc( inAppleEvent, inKeyword, typeChar );
-
- if ( theDesc.mDesc.descriptorType != typeNull ) {
- Handle theDataH = theDesc.mDesc.dataHandle;
- theTextLen = ::GetHandleSize( theDataH );
- ::SetHandleSize( theTextH, theTextLen );
- ThrowIfOSErr_( ::MemError() );
- ::BlockMoveData( *theDataH, *theTextH, theTextLen );
- } else {
- theTextLen = 0;
- ::SetHandleSize( theTextH, theTextLen );
- ThrowIfOSErr_( ::MemError() );
- result = false;
- }
-
- return result;
- }
-
-
- // --------------------------------------------------
- // • PutParamText
- // --------------------------------------------------
-
- void
- UAppleEvents::PutParamText(
- AppleEvent & ioAppleEvent,
- AEKeyword inKeyword,
- Handle theTextH,
- long theTextLen )
- {
- StHandleLocker theHandleLock( theTextH );
-
- StAEDescriptor theDesc( typeChar, *theTextH, theTextLen );
-
- OSErr err;
- err = ::AEPutParamDesc( &ioAppleEvent, inKeyword, &theDesc.mDesc );
- ThrowIfOSErr_( err );
- }
-
-
- // --------------------------------------------------
- // • PutParamFSSpec
- // --------------------------------------------------
-
- void
- UAppleEvents::PutParamFSSpec(
- AppleEvent & ioAppleEvent,
- AEKeyword inKeyword,
- const FSSpec & inFSSpec )
- {
- OSErr err;
-
- AliasHandle theAliasH;
- err = ::NewAliasMinimal( &inFSSpec, &theAliasH );
- ThrowIfOSErr_( err );
-
- ::HLock( (Handle) theAliasH );
-
- StAEDescriptor theDesc( typeAlias, (Ptr)*theAliasH, (**theAliasH).aliasSize );
-
- err = ::AEPutParamDesc( &ioAppleEvent, inKeyword, &theDesc.mDesc );
- ThrowIfOSErr_( err );
-
- ::HUnlock( (Handle) theAliasH );
-
- ::DisposeHandle( (Handle) theAliasH );
- }
-
-
- // --------------------------------------------------
- // • AddFSSpec
- // --------------------------------------------------
-
- void
- UAppleEvents::AddFSSpec(
- AEDescList & ioDescList,
- long inIndex,
- const FSSpec & inFSSpec )
- {
- OSErr err;
-
- AliasHandle theAliasH;
- err = ::NewAliasMinimal( &inFSSpec, &theAliasH );
- ThrowIfOSErr_( err );
-
- ::HLock( (Handle) theAliasH );
-
- err = ::AEPutPtr( &ioDescList, inIndex, typeAlias,
- (Ptr) *theAliasH, (**theAliasH).aliasSize );
- ThrowIfOSErr_( err );
-
- ::HUnlock( (Handle) theAliasH );
-
- ::DisposeHandle( (Handle) theAliasH );
- }
-
-
- // --------------------------------------------------
- // • PutParamFullPathname
- // --------------------------------------------------
-
- void
- UAppleEvents::PutParamFullPathname(
- AppleEvent & ioAppleEvent,
- AEKeyword inKeyword,
- ConstStr255Param inFullPathname )
- {
- OSErr err;
-
- AliasHandle theAliasH;
- err = ::NewAliasMinimalFromFullPath( inFullPathname[0], &inFullPathname[1], "\p", "\p", &theAliasH );
- ThrowIfOSErr_( err );
-
- ::HLock( (Handle) theAliasH );
-
- StAEDescriptor theDesc( typeAlias, (Ptr)*theAliasH, (**theAliasH).aliasSize );
-
- err = ::AEPutParamDesc( &ioAppleEvent, inKeyword, &theDesc.mDesc );
- ThrowIfOSErr_( err );
-
- ::HUnlock( (Handle) theAliasH );
-
- ::DisposeHandle( (Handle) theAliasH );
- }
-
-
- // --------------------------------------------------
- // • AddFullPathname
- // --------------------------------------------------
-
- void
- UAppleEvents::AddFullPathname(
- AEDescList & ioDescList,
- long inIndex,
- ConstStr255Param inFullPathname )
- {
- OSErr err;
-
- AliasHandle theAliasH;
- err = ::NewAliasMinimalFromFullPath( inFullPathname[0], &inFullPathname[1], "\p", "\p", &theAliasH );
- ThrowIfOSErr_( err );
-
- ::HLock( (Handle) theAliasH );
-
- err = ::AEPutPtr( &ioDescList, inIndex, typeAlias,
- (Ptr)*theAliasH, (**theAliasH).aliasSize );
- ThrowIfOSErr_( err );
-
- ::HUnlock( (Handle) theAliasH );
-
- ::DisposeHandle( (Handle) theAliasH );
- }
-
-
- // end of program
-